package com.laozhao.deliveryManager.view.delivery;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import com.laozhao.deliveryManager.model.entity.TransDeliveryDetail;
import com.laozhao.deliveryManager.zgui.ZPanel;
import com.laozhao.dreamframe.view.DreamTable;
import com.laozhao.dreamframe.view.DreamTableModel;

public class DeliverPanel extends ZPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7469929808584352274L;
	
	private JTextField customerComboBox;
	private JTextField addressField;
	private JTextField sendDateField;
	private JTextField sendNoField;
	private DreamTable table;
	private DreamTableModel<TransDeliveryDetail> model;
	
	private JButton saveButton ;
	private JButton clearButton;
	private JButton printButton;
	private JButton previewButton ;


	public DeliverPanel() {
		initCompant();
		
	}
	
//	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
//		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//		DeliverPanel x = new DeliverPanel();
//		JFrame frame = new JFrame();
//		frame.getContentPane().add(x);
//		frame.pack();
//		frame.setVisible(true);
//	}
	
	private void initCompant(){
		// dim panel
		JPanel viewpanel = new JPanel();
		JPanel controlPanel = new JPanel();
		JPanel mainDeliveryPanel = new JPanel();
		JScrollPane detailDeliveryPanel ;
		
		// dim layout
		setLayout(new BorderLayout(0, 0));
		viewpanel.setLayout(new GridLayout(2,1,5,5));
		
		// create view
		// control panel
		saveButton = new JButton("保存");
		clearButton = new JButton("清除");
		printButton = new JButton("打印");
		previewButton = new JButton("打印预览");
		controlPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		controlPanel.add(saveButton);
		controlPanel.add(clearButton);
		controlPanel.add(printButton);
		controlPanel.add(previewButton);
		mainDeliveryPanel.setLayout(new GridLayout(2, 4, 5, 2));
		
		// main delivery panel
		JLabel customerNameLabel = new JLabel("收货单位");
		customerNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		mainDeliveryPanel.add(customerNameLabel);
//		customerNameLabel.set
		
		customerComboBox = new JTextField();
		mainDeliveryPanel.add(customerComboBox);
		customerComboBox.setPreferredSize(new Dimension(100, 20));
		
		JLabel label = new JLabel("日期");
		label.setHorizontalAlignment(SwingConstants.RIGHT);
		mainDeliveryPanel.add(label);
		
		sendDateField = new JTextField();
		mainDeliveryPanel.add(sendDateField);
		sendDateField.setColumns(5);
		
		// detail delivery panel
		model = new DreamTableModel<TransDeliveryDetail>(TransDeliveryDetail.class);
		table = new DreamTable(model);
//		detailDeliveryPanel = new JScrollPane(table);
		detailDeliveryPanel = new JScrollPane(table);
//		detailDeliveryPanel.setViewportView(table);
		
		// add view
		viewpanel.add(controlPanel);
		viewpanel.add(mainDeliveryPanel);
		
		JLabel addressLabel = new JLabel("收货地址");
		mainDeliveryPanel.add(addressLabel);
		addressLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		
		addressField = new JTextField();
		mainDeliveryPanel.add(addressField);
		addressField.setColumns(20);		
		
		JLabel sendNoLabel = new JLabel("送货单号");
		mainDeliveryPanel.add(sendNoLabel);
		sendNoLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		
		sendNoField = new JTextField();
		mainDeliveryPanel.add(sendNoField);
		sendNoField.setColumns(5);
//		viewpanel.setSize(400, 800);
//		JPanel tablePanel = new JPanel();
//		tablePanel.add(detailDeliveryPanel);
		
		this.add(viewpanel, BorderLayout.NORTH);
		this.add(detailDeliveryPanel, BorderLayout.CENTER);
		
	}
}
